//
//  GoalNode.cpp
//  kasama1
//
//  Created by 丁逸鹏 on 15/3/3.
//
//

#include "GoalNode.h"
void GoalNode::onEnter()
{
    Node::onEnter();
    num=global->needpatriesindexnum[index];
    scoreLabel=LabelAtlas::create("0123456789", "shu2.png",26,31,'0');
    scoreLabel->setPosition(Vec2(0,-15));
    scoreLabel->setAnchorPoint(Vec2(0.5,0.5));
    isOk=Sprite::create("images/ok.png");
    isOk->setScale(0.25);
    isOk->setPosition(scoreLabel->getPosition());
    isOk->setVisible(false);
    addChild(isOk);
    addChild(scoreLabel);
    scoreLabel->runAction(FadeIn::create(1));
    scoreLabel->setScale(0.5);
    char spname[30];
    sprintf(spname,"%d",num);
    scoreLabel->setString(spname);
    sprintf(spname,"images/Pastries/%d.png",global->needpatriesindex[index]);
    pastry=Sprite::create(spname);
    pastry->setPosition(Vec2(0,200));
    pastry->setScale(0.5);
    
    addChild(pastry);
    pastry->runAction(MoveTo::create(1,Vec2(0,20)));
    schedule(schedule_selector(GoalNode::updateNum),0.1);
}
GoalNode::GoalNode(int index)
{
    this->index=index;
    //	onEnter();
}
void GoalNode::updateNum(float dt)
{
    if(global->needpatriesindexnum[index]<=0)
    {
        global->needpatriesindexnum[index]=0;
        char spname[30];
        sprintf(spname,"%d",num);
        scoreLabel->setVisible(false);
        isOk->setVisible(true);
    }
    //num=global->needpatriesindexnum[index];
    if(num!=global->needpatriesindexnum[index])
    {
        num--;
        char spname[30];
        sprintf(spname,"%d",num);
        scoreLabel->setString(spname);
    }
    
}